package com.ruoyi.lm.controller;

import java.util.List;

import com.ruoyi.lm.service.ILmActivityService;
import com.ruoyi.lm.service.ILmRequireService;
import com.ruoyi.lm.service.ILmSerinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmUsersign;
import com.ruoyi.lm.service.ILmUsersignService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务需求活动报名Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/lm/usersign")
public class LmUsersignController extends BaseController
{
    private String prefix = "lm/usersign";

    @Autowired
    private ILmUsersignService lmUsersignService;
    @Autowired
    private ILmRequireService lmRequireService;
    @Autowired
    private ILmSerinfoService lmSerinfoService;
    @Autowired
    private ILmActivityService lmActivityService;

    @RequiresPermissions("lm:usersign:view")
    @GetMapping()
    public String usersign()
    {
        return prefix + "/usersign";
    }

    /**
     * 查询服务需求活动报名列表
     */
    @RequiresPermissions("lm:usersign:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmUsersign lmUsersign)
    {
        startPage();
        List<LmUsersign> list = lmUsersignService.selectLmUsersignList(lmUsersign);
        for(LmUsersign temp :list){
            if("0".equals(temp.getSignType())){
                temp.setRequireTitle(lmRequireService.selectLmRequireById(temp.getSignId()).getRequireTitle());
            }
            if("1".equals(temp.getSignType())){
                temp.setServiceTitle(lmSerinfoService.selectLmSerinfoById(temp.getSignId()).getServiceTitle());
            }
            if("2".equals(temp.getSignType())){
                temp.setActivityTitle(lmActivityService.selectLmActivityById(temp.getSignId()).getActivityTitle());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出服务需求活动报名列表
     */
    @RequiresPermissions("lm:usersign:export")
    @Log(title = "服务需求活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmUsersign lmUsersign)
    {
        List<LmUsersign> list = lmUsersignService.selectLmUsersignList(lmUsersign);
        ExcelUtil<LmUsersign> util = new ExcelUtil<LmUsersign>(LmUsersign.class);
        return util.exportExcel(list, "usersign");
    }

    /**
     * 新增服务需求活动报名
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务需求活动报名
     */
    @RequiresPermissions("lm:usersign:add")
    @Log(title = "服务需求活动报名", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmUsersign lmUsersign)
    {
        return toAjax(lmUsersignService.insertLmUsersign(lmUsersign));
    }

    /**
     * 修改服务需求活动报名
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmUsersign lmUsersign = lmUsersignService.selectLmUsersignById(id);
        mmap.put("lmUsersign", lmUsersign);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务需求活动报名
     */
    @RequiresPermissions("lm:usersign:edit")
    @Log(title = "服务需求活动报名", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmUsersign lmUsersign)
    {
        return toAjax(lmUsersignService.updateLmUsersign(lmUsersign));
    }

    /**
     * 删除服务需求活动报名
     */
    @RequiresPermissions("lm:usersign:remove")
    @Log(title = "服务需求活动报名", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmUsersignService.deleteLmUsersignByIds(ids));
    }
}
